<template>
<div class="chat-left-nav">
    <div class="left-nav" v-if="!webConfig.menus">
        <div
            v-for="item in 6"
            :key="item"
        >
            <div class="chat-nav-item">
                <a-skeleton-button active size="large" shape="circle" />
            </div>
        </div>
    </div>
    <div class="left-nav" v-else>
        <div
            v-for="item in webConfig.menus"
            :key="item.id"
        >
            <a-tooltip placement="right">
                <template #title>{{ item.name }}</template>
                <div>
                    <div
                        @click="urlToPath(item)"
                    >
                        <div
                            class="chat-nav-item"
                            :class="{ active: is_menu_toggle === item.path }"
                        >
                            <Icon :name="item.icon" size="24" />
                        </div>
                    </div>
                </div>
            </a-tooltip>
        </div>
    </div>
</div>
</template>

<script setup lang="ts">
import {inject, reactive, ref, watch} from "vue"
import { useAiConfig } from '/@/stores/aiConfig'
import {useRoute, useRouter} from "vue-router";
import {useUserInfo} from "/@/stores/userInfo";

const userInfo = useUserInfo()
const route = useRoute()
const router = useRouter()
const is_menu_toggle = ref(route.name)
watch(() => route.name, (value) => {
    is_menu_toggle.value = value
})

const webConfig = useAiConfig()

const state = reactive({
    loading: false,
    login_show: inject('login_show', ref(false)),
})

function urlToPath(item: any) {
    if (!userInfo.isLogin() && item.no_login_valid == 1) {
        state.login_show = !state.login_show
        return
    }

    if (item.menu_type == 'iframe') {
        router.push('/iframe?u=' + btoa(item.url))
    } else {
        router.push(item.url)
    }
}
</script>

<style scoped lang="scss">
.chat-left-nav {
    flex: 1 1;
    margin-top: 16px;
    gap: 16px;
    overflow: hidden;
    .left-nav {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 8px;
        max-height: 500px;
        overflow-y: scroll;
        &::-webkit-scrollbar {
            display: none;
        }
    }
    .chat-nav-item {
        display: flex;
        width: 44px;
        height: 44px;
        border-radius: 12px;
        color: var(--el-text-color-primary);
        justify-content: center;
        align-items: center;
        cursor: pointer;
        &:hover, &.active {
            color: var(--text-color-black1);
            background-color: var(--ct-navbg-color);
        }
    }
}

@media (max-width: 768px) {

}
</style>
